<template>
  <!-- 停车场长租账单  -->
    <div class="interestCalculationDetailsPage">
        <div class="search-wrap d-flex flex-wrap">
            <div class="search-item d-flex a-center m-l20">
                <label>订单时间</label>
                <el-date-picker
                        class="m-l10"
                        size="large"
                        v-model="form.longParkingLotDate"
                        value-format="YYYY-MM-DD"
                        type="date"
                        placeholder="请选择订单时间"
                />
            </div>
            <div class="search-buttons m-l50 d-flex a-center">
                <el-button
                        color="#fc702b"
                        style="color:#fff;"
                        @click.prevent="onQuery"
                >查询</el-button>
                <el-button
                        color="#f0f0f0"
                        style="color: #000000"
                        @click.prevent="onReset"
                >重置</el-button>
                <el-divider class="m-l50 m-r50" direction="vertical" />
                <el-button
                    @click="queryTotal"
                    class="button_edit m-r10"
                >
                    查看合计
                </el-button>
                <el-button
                        class="button_edit"
                        @click="onImport"
                >
                    导入
                </el-button>
                <el-button
                        class="button_edit"
                        @click="onTemplateExport"
                >
                    模版导出
                </el-button>
                <el-button
                        class="button_edit"
                        @click="onExport"
                >
                    <svg-icon icon-class="project-detail-icon-derive" class="icon-export m-r5"></svg-icon>
                    一键导出
                </el-button>
            </div>
        </div>
        <public-table
                ref="publicTableRef"
                class="m-t20"
                index
                :indexWidth="'100'"
                :page="page"
                :tableData="tableData"
                :tableOption.sync="tableOption"
                @page-change="onPageChange"
        ></public-table>
    </div>

  <!-- 导入excel   -->
    <public-dialog
            :title="'导入体育馆订单'"
            :width="'40%'"
            :confirmButtonTitle="'确认'"
            v-model:visible="visible"
            @onConfirm="onConfirm"
    >
        <div class="public-dialog-content d-flex flex-column">
            <el-upload
                    ref="uploadRef"
                    class="upload-demo"
                    drag
                    action="#"
                    multiple
                    :http-request="uploadFile"
            >
                <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                <div class="el-upload__text">
                    将文件拖到此处或<em>点击上传</em>
                </div>
            </el-upload>
        </div>
    </public-dialog>

    <!-- 查看合计   -->
    <public-dialog
        :title="'查看合计'"
        :width="'80%'"
        :confirmButtonTitle="'确认'"
        v-model:visible="visible2"
        @onConfirm="onConfirm2"
    >
        <div class="public-dialog-content d-flex flex-column">
            <public-table
                :header-cell-style="{'background':'#F5F5F5'}"
                border
                :index="false"
                :is-paging="false"
                :tableData="tableData2"
                :tableOption.sync="tableOption2"
            ></public-table>
        </div>
    </public-dialog>
</template>

<script setup>
import {onMounted, reactive, ref} from "vue";
import {
    ElDivider,
    ElDatePicker, ElUpload, ElLoading, ElMessage
} from "element-plus";
import PublicTable from "@/components/PublicTable.vue";
import {tableCommonFun} from "@/hooks/tableCommon";
import {UploadFilled} from "@element-plus/icons-vue";
import PublicDialog from "@/components/PublicDialog.vue";
import {physicalCultureApi} from "@/api/businessFinance";
import {exportExcelFile} from "@/common/utils/GlobalUtils";

const interfaceConfig = reactive({
    fileName:'businessFinance',
    apiPath:'physicalCultureApi.bfFinanceLongParkingLotPage',
});
const exportConfig = reactive({
    fileName:'businessFinance',
    apiPath:'physicalCultureApi.bfFinanceLongParkingLotExport',
    tableName:'停车场长租账单表'
});
const {
    form,
    page,
    tableOption,
    tableData,
    onQuery,
    onReset,
    onPageChange,
    getData,
    onExport
}  = tableCommonFun(interfaceConfig,exportConfig);

form.value = {
    longParkingLotDate:''
}

tableOption.value = [
    { label: "日期 ", prop: "longParkingLotDate", minWidth: 160 },
    { label: "现金收取（开通&续费）", prop: "longParkingLotCashMoney", minWidth: 180 },
    { label: "车位数（开通&续费） ", prop: "longParkingLotCashNumber", minWidth: 160 },
    { label: "现金退费（退费） ", prop: "longParkingLotCashRefund", minWidth: 150 },
    { label: "车位数（退费） ", prop: "longParkingLotCashRefundNumber", minWidth: 150 },
    { label: "电子支付（APP续费）", prop: "longParkingLotCashElectron", minWidth: 180 },
    { label: "车位数（APP续费）", prop: "longParkingLotCashElectronNumber", minWidth: 150 },
    { label: "收入合计（长租汇总）", prop: "longParkingLotCashAllMoney", minWidth: 180 },
    { label: "有效车位总数（长租汇总）", prop: "effectiveNumber", minWidth: 200 },
];

/**
 * 导入确认按钮
 */
const visible = ref(false);
const onConfirm = () => {
    visible.value = false;
}

/**
 * 导入按钮
 */
const onImport = () => {
    visible.value = true;
}

/**
 * 模版导出按钮
 */
const onTemplateExport = () => {
    physicalCultureApi.bfFinanceLongParkingLotTemplate().then(res=>{
        if(res){
            exportExcelFile(res,'停车场长租账单模版');
        }else{
            ElMessage.error('导出失败!');
        }
    });
}

/**
 * 上次文件方法
 * @param file
 */
const uploadFile = (file) => {
    const loading = ElLoading.service({
        lock: true,
        text: "Loading",
        background: "rgba(0, 0, 0, 0.7)",
    });
    let uploadFile = new FormData();
    uploadFile.append("file", file.file);
    physicalCultureApi.importExcelBfFinanceLongParkingLot(uploadFile).then(res=>{
        if (res.code === '200') {
            loading.close();
            ElMessage.success("上传成功!");
            visible.value = false;
            getData({
                pageNum:1,
                pageSize:10,
                param:{}
            });
        }else{
            loading.close();
            ElMessage.error("上传失败!请联系管理员。");
        }
    });
}

const tableOption2 = ref([
    { label: "现金收取合计", prop: "longParkingLotCashMoneyAll", minWidth: 120 },
    { label: "车位数合计", prop: "longParkingLotCashNumberAll", minWidth: 100 },
    { label: "现金退费合计", prop: "longParkingLotCashRefundAll", minWidth: 120 },
    { label: "车位数合计", prop: "longParkingLotCashRefundNumberAll", minWidth: 100 },
    { label: "电子支付合计", prop: "longParkingLotCashElectronAll", minWidth: 120 },
    { label: "车位数合计", prop: "longParkingLotCashElectronNumberAll", minWidth: 100 },
    { label: "收入合计", prop: "longParkingLotCashAllMoneyAll", minWidth: 80 },
    { label: "有效车位总数合计", prop: "effectiveNumberAll", minWidth: 150 },
]);
const tableData2  = ref([]);

/**
 * 查看合计确认按钮
 *
 */
const visible2 = ref(false);
const onConfirm2 = () => {
    visible2.value = false;
}

/**
 * 查看合计
 */
const queryTotal = () => {
    visible2.value = true;
    physicalCultureApi.bfFinanceLongParkingLotAmount({}).then(res=>{
        tableData2.value = [{...res.data}];
    });
}

onMounted(()=>{
    getData({
        pageNum:1,
        pageSize:10,
        param:{}
    });
});
</script>

<style lang="scss" scoped>
.interestCalculationDetailsPage{
  .search-wrap{
    .search-item{

      .el-input{
        width: auto !important;
      }
    }
    .search-buttons{
      .icon-export{
        width: 18px;
        height: 18px;
      }
    }
  }
}
.public-dialog-content{
  .dialog-title-box{
    height: 30px;
    span{
      font-size: 15px;
      font-weight: 600;
    }
  }
}
</style>
